package com.javarush.test.level21.lesson16.big01;

import java.util.ArrayList;

/**
 * Created by admin on 02.03.2015.
 */
public class Hippodrome {
    static ArrayList<Horse> horses=new ArrayList<>();

    public ArrayList<Horse> getHorses() {
        return horses;
    }

    public static Hippodrome game;

    public static void main(String[] args) {
        game=new Hippodrome();
        Horse horse1=new Horse("Murka",3,0);
        Horse horse2=new Horse("Zhuchka",3,0);
        Horse horse3=new Horse("Ryabaya",3,0);
        horses.add(horse1);
        horses.add(horse2);
        horses.add(horse3);
        game.run();
    }

    public void run(){
        for (int i=0;i<100;i++){
            move();
            print();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
        }
        printWinner();
    }
    public void move(){
        for(Horse horse: horses){
            horse.move();
        }
    }
    public void print(){
        for(Horse horse: horses){
            horse.print();
        }
        System.out.println();
        System.out.println();
    }

    public Horse getWinner(){
        Horse winner=null;
        double maxDist=0;
        for(Horse horse: horses){
            if (horse.distance>maxDist) {
                maxDist=horse.distance;
                winner=horse;
            }
        }
        return winner;
    }

    public void printWinner(){
        System.out.print("Winner is "+ getWinner().getName()+"!");
    }
}
